home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / dvivga9.zip / READPK.H < prev    next >
Text File  |  1988-05-30  |  6KB  |  167 lines

  1. /* -*-C-*- readpk.h */
  2. /*-->readpk*/
  3. /**********************************************************************/
  4. /******************************* readpk *******************************/
  5. /**********************************************************************/
  6.  
  7. int
  8. readpk()    /* return 0 on success, EOF on failure */
  9. {
  10.     UNSIGN32 checksum;
  11.     long end_of_packet;    /* pointer to byte following character packet */
  12.     register BYTE flag_byte;
  13.     UNSIGN32 packet_length;
  14.     long start_of_packet;    /* pointer to start of character packet */
  15.     register struct char_entry *tcharptr;/* temporary char_entry pointer */
  16.     register UNSIGN32 the_char;
  17.  
  18.     /* Read a PK file, extracting character metrics and raster
  19.        locations. */
  20.  
  21.     /******************************************************************/
  22.  
  23.     /* Process the preamble parameters */
  24.  
  25.     (void)REWIND(fontfp);    /* start at beginning of file */
  26.     if ((BYTE)nosignex(fontfp,(BYTE)1) != PKPRE)
  27.     {
  28.     (void)warning("readpk():  PK font file does not start with PRE byte");
  29.     return(EOF);
  30.     }
  31.     if ((BYTE)nosignex(fontfp,(BYTE)1) != PKID)
  32.     {
  33.     (void)warning(
  34.         "readpk():  PK font file PRE byte not followed by ID byte");
  35.     return(EOF);
  36.     }
  37.  
  38.     if (FSEEK(fontfp,(long)nosignex(fontfp,(BYTE)1),1))
  39.     {
  40.     (void)warning("readpk():  PK font file has garbled comment string");
  41.     return(EOF);        /* skip comment string */
  42.     }
  43.  
  44.     fontptr->designsize = nosignex(fontfp,(BYTE)4);
  45.  
  46.     checksum = nosignex(fontfp,(BYTE)4);    /* checksum */
  47.     if ((fontptr->c != 0L) && (checksum != 0L) && (fontptr->c != checksum))
  48.     {
  49.     (void)sprintf(message,
  50.     "readpk():  font [%s] has checksum = 10#%010lu [16#%08lx] [8#%011lo] \
  51. different from DVI checksum = 10#%010lu [16#%08lx] [8#%011lo].  \
  52. TeX preloaded .fmt file is probably out-of-date with respect to new fonts.",
  53.         fontptr->name, fontptr->c, fontptr->c, fontptr->c,
  54.         checksum, checksum, checksum);
  55.     (void)warning(message);
  56.     }
  57.  
  58.     fontptr->hppp = (UNSIGN32)nosignex(fontfp,(BYTE)4);
  59.     fontptr->vppp = (UNSIGN32)nosignex(fontfp,(BYTE)4);
  60.  
  61.     fontptr->min_m = 0L;    /* these are unused in PK format */
  62.     fontptr->max_m = 0L;
  63.     fontptr->min_n = 0L;
  64.     fontptr->max_n = 0L;
  65.  
  66.     fontptr->magnification = (UNSIGN32)( 0.5 + 5.0 * 72.27 *
  67.     (float)(fontptr->hppp) / 65536.0 );    /* from GFtoPXL Section 53 */
  68.  
  69.     /******************************************************************/
  70.     /* Process the characters until the POST byte is reached */
  71.  
  72.     (void)skpkspec();    /* skip any PK specials */
  73.  
  74.     start_of_packet = (long)FTELL(fontfp);
  75.     while ((flag_byte = (BYTE)nosignex(fontfp,(BYTE)1)) != PKPOST)
  76.     {
  77.     flag_byte &= 0x07;
  78.     switch(flag_byte)    /* flag_byte is in 0..7 */
  79.     {
  80.     case 0:
  81.     case 1:
  82.     case 2:
  83.     case 3:        /* short character preamble */
  84.         packet_length = (UNSIGN32)flag_byte;
  85.         packet_length <<= 8;
  86.         packet_length += (UNSIGN32)nosignex(fontfp,(BYTE)1);
  87.         the_char = (UNSIGN32)nosignex(fontfp,(BYTE)1);
  88.         if (the_char >= NPXLCHARS)
  89.         {
  90.         (void)warning(
  91.         "readpk():  PK font file character number is too big for me");
  92.             return(EOF);
  93.         }
  94.         tcharptr = &(fontptr->ch[the_char]);
  95.         end_of_packet = (long)FTELL(fontfp) + (long)packet_length;
  96.         tcharptr->tfmw = (UNSIGN32)(((float)nosignex(fontfp,(BYTE)3) *
  97.         (float)fontptr->s) / (float)(1L << 20));
  98.         tcharptr->dx = (INT32)nosignex(fontfp,(BYTE)1) << 16;
  99.         tcharptr->dy = 0L;
  100.         tcharptr->pxlw = (UNSIGN16)PIXROUND(tcharptr->dx, 1.0/65536.0);
  101.         tcharptr->wp = (COORDINATE)nosignex(fontfp,(BYTE)1);
  102.         tcharptr->hp = (COORDINATE)nosignex(fontfp,(BYTE)1);
  103.         tcharptr->xoffp = (COORDINATE)signex(fontfp,(BYTE)1);
  104.         tcharptr->yoffp = (COORDINATE)signex(fontfp,(BYTE)1);
  105.         break;
  106.  
  107.     case 4:
  108.     case 5:
  109.     case 6:        /* extended short character preamble */
  110.         packet_length = (UNSIGN32)(flag_byte & 0x03);
  111.         packet_length <<= 16;
  112.         packet_length += (UNSIGN32)nosignex(fontfp,(BYTE)2);
  113.         the_char = (UNSIGN32)nosignex(fontfp,(BYTE)1);
  114.         if (the_char >= NPXLCHARS)
  115.         {
  116.         (void)warning(
  117.         "readpk():  PK font file character number is too big for me");
  118.             return(EOF);
  119.         }
  120.         tcharptr = &(fontptr->ch[the_char]);
  121.         end_of_packet = (long)FTELL(fontfp) + (long)packet_length;
  122.         tcharptr->tfmw = (UNSIGN32)(((float)nosignex(fontfp,(BYTE)3) *
  123.         (float)fontptr->s) / (float)(1L << 20));
  124.         tcharptr->dx = (INT32)nosignex(fontfp,(BYTE)2) << 16;
  125.         tcharptr->dy = 0L;
  126.         tcharptr->pxlw = (UNSIGN16)PIXROUND(tcharptr->dx, 1.0/65536.0);
  127.         tcharptr->wp = (COORDINATE)nosignex(fontfp,(BYTE)2);
  128.         tcharptr->hp = (COORDINATE)nosignex(fontfp,(BYTE)2);
  129.         tcharptr->xoffp = (COORDINATE)signex(fontfp,(BYTE)2);
  130.         tcharptr->yoffp = (COORDINATE)signex(fontfp,(BYTE)2);
  131.         break;
  132.  
  133.     case 7:        /* long character preamble */
  134.         packet_length = (UNSIGN32)nosignex(fontfp,(BYTE)4);
  135.         the_char = (UNSIGN32)nosignex(fontfp,(BYTE)4);
  136.         if (the_char >= NPXLCHARS)
  137.         {
  138.         (void)warning(
  139.         "readpk():  PK font file character number is too big for me");
  140.             return(EOF);
  141.         }
  142.         tcharptr = &(fontptr->ch[the_char]);
  143.         end_of_packet = (long)FTELL(fontfp) + (long)packet_length;
  144.         tcharptr->tfmw = (UNSIGN32)(((float)nosignex(fontfp,(BYTE)4) *
  145.         (float)fontptr->s) / (float)(1L << 20));
  146.         tcharptr->dx = (INT32)signex(fontfp,(BYTE)4);
  147.         tcharptr->dy = (INT32)signex(fontfp,(BYTE)4);
  148.         tcharptr->pxlw = (UNSIGN16)PIXROUND(tcharptr->dx, 1.0/65536.0);
  149.         tcharptr->wp = (COORDINATE)nosignex(fontfp,(BYTE)4);
  150.         tcharptr->hp = (COORDINATE)nosignex(fontfp,(BYTE)4);
  151.         tcharptr->xoffp = (COORDINATE)signex(fontfp,(BYTE)4);
  152.         tcharptr->yoffp = (COORDINATE)signex(fontfp,(BYTE)4);
  153.         break;
  154.     } /* end switch */
  155.     tcharptr->fontrp = start_of_packet;
  156.     (void)FSEEK(fontfp,end_of_packet,0); /* position to end of packet */
  157.     (void)skpkspec();    /* skip any PK specials */
  158.     start_of_packet = (long)FTELL(fontfp);
  159.     } /* end while */
  160.  
  161. #if    (BBNBITGRAPH | HPJETPLUS | POSTSCRIPT | IMPRESS | CANON_A2)
  162.     (void)newfont();
  163. #endif
  164.  
  165.     return(0);
  166. }
  167.